package com.jack.leetcode.array;

/*** 
 * @author zhangjie
 * @date 2020/3/25 21:16
 */
public class 买卖股票的最佳时机 {

    public static void main(String[] args) {
        int []a = {7,1,5,3,6,4};
        int []b = {7,6,4,3,1};
        System.out.println(maxProfit(a));
        System.out.println(maxProfit(b));
    }

    public static int maxProfit(int[] prices) {
        int result = 0;
        for(int i=0;i<prices.length-1;i++){
            for(int j=i+1;j<prices.length;j++){
                if(prices[j]-prices[i]>result){
                    result = prices[j]-prices[i];
                }
            }
        }
        return result;
    }
}
